<template>
	<view>
		<view class="editinfo-page flex">
			<view class="nickname-wrap flex">
				<view class="nickname-wrap__tips flex">
					<u-text text="真实姓名" color="#999" :size="28"></u-text>
				</view>
				<view class="nickname-wrap__input flex">
					<input type="text" v-model="idcheckInfo.realname" placeholder="请输入真实姓名" />
				</view>
			</view>
			
			<view class="nickname-wrap flex">
				<view class="nickname-wrap__tips flex">
					<u-text text="身份证号" color="#999" :size="28"></u-text>
				</view>
				<view class="nickname-wrap__input flex">
					<input type="idcard" v-model="idcheckInfo.idnumber" placeholder="请输入身份证号" />
				</view>
			</view>
			
			<view class="nickname-wrap flex">
				<view class="nickname-wrap__tips flex">
					<u-text text="家庭住址" color="#999" :size="28"></u-text>
				</view>
				<view class="nickname-wrap__input flex">
					<input type="text" v-model="idcheckInfo.address" placeholder="请输入家庭住址" />
				</view>
			</view>
			
			<view class="nickname-wrap flex" v-if="idcheckInfo.check_time">
				<view class="nickname-wrap__tips flex">
					<u-text text="认证时间" color="#999" :size="28"></u-text>
				</view>
				<view class="nickname-wrap__input flex">
					<input type="text" :disabled="true" v-model="idcheckInfo.check_time" />
				</view>
			</view>
			
			<view class="info-save" @click="confirmSave()">确定保存</view>
		</view>
	</view>
</template>

<script>
	import { idcardInfo,idcardInfoSave } from '@/api/api.js'
	
	export default {
		data() {
			return {
				idcheckInfo: {
					realname: '',
					idnumber: '',
					address: ''
				}
			}
		},
		mounted() {
			idcardInfo().then(res => {
				this.idcheckInfo = res.data
			})
		},
		methods: {
			confirmSave: function() {
				if ( !this.idcheckInfo.realname ) {
					return uni.showToast({
					    title: '请填写真实姓名~',
					    icon: 'none'
					})
				}
				if ( !this.idcheckInfo.idnumber ) {
					return uni.showToast({
					    title: '请填写身份证号~',
					    icon: 'none'
					})
				}
				if ( !uni.$lv.validate.idCard(this.idcheckInfo.idnumber) ) {
					return uni.showToast({
					    title: '请填写正确的身份证号~',
					    icon: 'none'
					})
				}
				if ( !this.idcheckInfo.address ) {
					return uni.showToast({
					    title: '请填写身份证户籍地址~',
					    icon: 'none'
					})
				}

				uni.showLoading({
					title: '数据保存中'
				})
				idcardInfoSave(this.idcheckInfo).then( _ => {
					uni.hideLoading()
					
					// 更新本地用户实名标识
					let userInfo = uni.getStorageSync('ftxUserInfo') || {}
					userInfo.is_idcheck = 1
					uni.setStorageSync('ftxUserInfo' , userInfo)
	
					uni.showToast({
						title: '保存成功~',
						icon: 'none',
						duration: 2000,
						success() {
							setTimeout(function(){
								uni.navigateBack()
							},2500)
						}
					})
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.editinfo-page {
	margin-top: 60rpx;
	align-items: center;
	flex-direction: column;
	.avatar-wrap {
		flex-direction: column;
		align-items: center;
		justify-content: center;
		margin-bottom: 80rpx;
		&__tips {
			margin-top: 8rpx;
		}
	}
	.nickname-wrap {
		width: 90%;
		justify-content: center;
		margin-bottom: 26rpx;
		&__tips {
			width: 140rpx;
			@include flex;
			align-items: center;
		}
		&__input {
			@include flex;
			flex: 1;
			border-bottom: 1rpx solid $uni-text-color-disable;
			padding-bottom: 12rpx;
			color: $uni-text-color-placeholder;
			font-size: 28rpx;
			justify-content: space-between;
			align-items: center;
			input {
				width: 100%;
			}
		}
	}
	
	.info-save {
		@include flex;
		box-shadow: 0upx 5upx 10upx rgba(0, 0, 0, 0.2);
		width: 90%;
		height: 80upx;
		text-align: center;
		border-radius: 80upx;
		background-color: #f23a3a;
		color: #fff;
		justify-content: center;
		align-items: center;
		font-size: 30upx;
		margin-top: 40upx;
	}
}
</style>
